<template>
	<view class="padding-20">
		<!-- 地址 -->
		<!-- <view class="flex-between flex-boderRadius-view bg-fff padding-20 margin-bottom30" v-if="false">
			<image class="img-40 margin-right20" src="../../static/index/07.png" mode="widthFix"></image>
			<view class="flex-column flex1">
				<view class="fontSize-18 color-000 fontWeight-bold">添加收货信息</view>
				<view class="fontSize-13 color-999 margin-top10">请完善收货信息</view>
			</view>
			<u-icon name="arrow-right" color="#333333" size="20"></u-icon>
		</view>
		
		<view class="flex-between flex-boderRadius-view bg-fff padding-20 margin-bottom30" v-else>
			<image class="img-40 margin-right20" src="../../static/index/07.png" mode="widthFix"></image>
			<view class="flex-column flex1">
				<view class="fontSize-18 color-000 fontWeight-bold">张三 18898547858</view>
				<view class="fontSize-13 color-999 margin-top10">河南省 郑州市 金水区 郑花路59号居易摩根中心</view>
			</view>
			<u-icon name="arrow-right" color="#333333" size="20"></u-icon>
		</view> -->
		
		<view class="flex-between flex-boderRadius-view bg-fff padding-20 margin-bottom30" v-if="address.id"
		@click="goToUrl">
			<view class="margin-right20">
				<u-icon name="map" color="#333333" size="20"></u-icon>
			</view>
			<view class="flex-column flex1">
				<view class="fontSize-18 color-000 fontWeight-bold">{{address.name}} {{address.mobile}}</view>
				<view class="fontSize-13 color-999 margin-top10">{{address.area}}{{address.address}}</view>
			</view>
			<u-icon name="arrow-right" color="#333333" size="20"></u-icon>
		</view>
		<view class="flex-between flex-boderRadius-view bg-fff padding-20 margin-bottom30"  v-else
		@click="goToUrl">
			<view class="margin-right20">
				<u-icon name="map" color="#333333" size="20"></u-icon>
			</view>
			<view class="flex-column flex1">
				<view class="fontSize-18 color-000 fontWeight-bold">添加收货信息(非必填)</view>
				<view class="fontSize-13 color-999 margin-top10">请完善收货信息</view>
			</view>
			<u-icon name="arrow-right" color="#333333" size="20"></u-icon>
		</view>	
		
		
		
		<!-- 商品信息 -->
		<view class="flex-boderRadius-view bg-fff padding-20 margin-bottom20">
			<view class="flex margin-bottom20" v-for="(item,index) in cartList" :key="index">
				<image class="img-160 margin-right20 border-radius10" :src="item.image" mode=""></image>
				<view class="flex1 flex-column">
					<view class="fontSize-16 color-000 margin-bottom10">{{item.title}}</view>
					<view class="fontSize-16 color-000 margin-bottom10">{{item.item_name}}</view>
					<view class="flex-between">
						<view class="fontSize-13 color-FE3232">￥<text class="fontSize-16">{{item.sum_price}}</text></view>
						<view class="fontSize-15 color-000">x{{item.count}}</view>
					</view>
				</view>
			</view>
			<view class="flex1 margin-bottom20 flex-between">
				<view class="fontSize-15 color-000">商品总金额</view>
				<view class="fontSize-15 color-000 margin-right10">￥{{totalPrice}}</view>
			</view>
			<view class="flex1 margin-bottom20 flex-between">
				<view class="fontSize-15 color-000">配送费用</view>
				<view class="fontSize-15 color-000 margin-right10">￥0</view>
			</view>
			<view class="flex1 margin-bottom20 flex-between">
				<view class="fontSize-15 color-000">总计实付</view>
				<view class="fontSize-15 color-000 margin-right10">￥{{totalPrice}}</view>
			</view>
		</view>
		
		<!-- 备注 -->
		<view class="flex-boderRadius-view bg-fff padding-20">
			<view class="fontSize-16 color-000 margin-bottom20">留言：</view>
			<view class="bg-f6f6f6">
				<u--textarea v-model="remark" height="100" placeholder="请输入内容" ></u--textarea>
			</view>
		</view>
		
		<!-- 底部操作栏 -->
		<view class="position-fixed-94bottom bg-fff padding-20 flex-between">
			<view class="btn-967C5E-15ffffff flex-center flex1" @click="confrimPay">
				 立即支付
			</view>
		</view>
		
		<!-- 积分弹窗 -->
		<!-- <u-popup :show="integralPopupShow" @close="integralPopupShow = false" :closeable="true">
			<view class="popup-view">
				<view class="fontSize-15 color-000 margin-bottom30">积分(150)</view>
				<view class="flex-between margin-bottom30">
					<view class="fontSize-13 color-000">暂不使用积分</view>
					<image class="img-32" src="../../static/index/08.png" mode="widthFix"></image>
				</view>
				<view class="flex-between margin-bottom30">
					<view class="fontSize-13 color-000">暂不使用积分</view>
					<image class="img-32" src="../../static/index/08.png" mode="widthFix"></image>
				</view>
			</view>
		</u-popup> -->
	</view>
</template>

<script>
	import {
		mapMutations
	} from 'vuex'
	export default {
		data(){
			return{
				value1: '',
				num:'',
				integralPopupShow:false,
				address: {},
				userinfo: {},
				// 备注
				remark: '',
				payWayIndex: 0,
				pay_type: 1,
				order_no: '',
				// 防抖
				isSubmit:true,
				cartList:[] //购物车列表
			}
		},
		onLoad(e) {
			console.log(e)
			if (e.address) {
				this.address = JSON.parse(e.address)
			}
			if(e.cartList){
				this.cartList = JSON.parse(e.cartList) 
				console.log(this.cartList)
			}
		},
		onShow() {
			if (this.$store.state.address.address.id) {
				this.address = this.$store.state.address.address
			}
			// this.getUserInfo()
		},
		onHide() {
			this.deleteAddressItem()
		},
		computed: {
			// 计算金额
			totalPrice(){
				let allPrice = 0
				this.cartList.forEach(v=>{
					allPrice += Number(v.sum_price)*v.count
				})
				return Number(allPrice).toFixed(2)
			}
		},
		methods:{
			...mapMutations(['deleteAddressItem']),
			goToUrl() {
				uni.navigateTo({
					url: '/pages/mine/mine-list/address/address?orderCode=' + '订单选择地址'
				})
			},
			// 确认支付
			async confrimPay() {
				if (!this.address.id) {
					return this.$tools.toast('请选择地址')
				}
				if(!this.isSubmit) return false
				this.isSubmit = false
				let cartIds = []
				cartIds = this.cartList.map(v=>{
					return v.id
				})
				console.log(cartIds)
				// cartIds = cartIds.join(',')
				let payForm = {
					cart_id:cartIds,
					goods_type:1,
					address_id: this.address.id,
					remark: this.remark
				}
				let res = await this.$http.post(this.$api.cart_order, payForm, {
					token: true
				})
				if (res.code == 1) {
					// this.order_no = res.data.order_no
					this.payOrder(res.data.order_no)
				}
			},
			// 支付
			async payOrder(order_no){
				// let res = await this.$http.post(this.$api.pay,{order_no:order_no,pay_type:1},{token:true})
				// let res = await this.$http.post(this.$api.cart_order_detail,{order_no:order_no},{token:true})
				let res = await this.$http.post(this.$api.order_test,{order_no:order_no},{token:true})
				console.log(res)
				this.isSubmit = true
				this.$tools.toast('支付成功')
				this.$tools.redirectTo('/pages/mine/order-list/order-list',200)
			}
		}
	}
</script>

<style lang="scss" scoped>
	
</style>